package com.example.springboot.service;

import com.example.springboot.dao.MyUserMapper;
import com.example.springboot.pojo.MyUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyUserServiceImpl implements MyUserService{
    @Autowired
    private MyUserMapper myUserMapper;

    @Cacheable(value = "myuser",key = "#id")
    @Override
    public List<MyUser> getUserById1(Integer id) {
        return myUserMapper.selectUserByid(id);
    }

    @CachePut(value = "myuser",key = "#id")
    @Override
    public int updateUserBuId(Integer id) {
        MyUser myUser = new MyUser();
        myUser.setId(id);
        myUser.setName("cccccc");
        return myUserMapper.insert(myUser);
    }

    @CacheEvict(value = "myuser")
    @Override
    public int updateUserBuId2(Integer id) {
        MyUser myUser = new MyUser();
        myUser.setId(id);
        myUser.setName("cccccc");
        return myUserMapper.insert(myUser);
    }

}
